{template 'common/header'}
<script>
    $(function(){
        $(".examine").on("click",function(){
            var order_id = $(this).attr('order_id');
            if(confirm('是否确认审核该订单款项？')){
//                var url = "{php echo $this->createWebUrl('finance',array('op' => 'examine_all'))}";
//                $.ajax({
//                    type : 'post',
//                    url : url,
//                    data : {'order_id' : order_id},
//                    success : function(data){
//                        if(data == 111){
//                            location.reload();
//                        }else{
//                            alert(data);
//                        }
//                    }
//                });
                var url = "{php echo $this->createWebUrl('finance',array('op' => 'examine'))}";
                var log_id = $(this).attr('log_id');
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'log_id' :log_id},
                    success : function(data){
                        if(data == 111){
                            alert("审核成功！");
                            location.reload();
                        }else{
                            alert(data);
                        }
                    }
                });
            }
        });
        $(".examine-all").on('click',function(){
            if(confirm("是否确定全部收款？")){
                var order_ids = {$log_ids};
                var url = "{php echo $this->createWebUrl('finance',array('op' => 'examine'))}";
                for(var i=0;i<order_ids.length;i++){
//                    alert(order_ids[i]);
                    $.ajax({
                        type : 'post',
                        url : url,
                        data : {'log_id' :order_ids[i]},
                        success : function(data){
//                            if(data == 111){
//                                alert("审核成功！");
//                                location.reload();
//                            }else{
//                                alert(data);
//                            }
                        }
                    });
                }
                alert("操作成功！");
                location.reload();
            }
        });
        $("#page-size").on('change',function(){
            find();
        });
        $(".find").on("click",function(){
           find();
        });
        $(".export").on("click",function(){
            var start_day = $("#start_day").val();
            var end_day = $("#end_day").val();
            var key_word = $("#key_word").val();
            var status = "{$status}";
            var user_id = $("#user_id").val();
            var psize = $("#page-size").val();
            var server_id = $("#server_id").val();
            var type = $("#type").val();
            location.href="{php echo $this->createWebUrl('finance')}&status="+status+"&key_word="+key_word+"&start_day="+start_day+"&end_day="+end_day+"&user_id="+user_id+"&psize="+psize+"&server_id="+server_id+"&type="+type+"&export=1";
        });
    });
    function find(){
        var start_day = $("#start_day").val();
        var end_day = $("#end_day").val();
        var key_word = $("#key_word").val();
        var status = "{$status}";
        var user_id = $("#user_id").val();
        var psize = $("#page-size").val();
        var server_id = $("#server_id").val();
        var type = $("#type").val();
        var examine_id = $("#examine-id").val();
        location.href="{php echo $this->createWebUrl('finance')}&status="+status+"&key_word="+key_word+"&start_day="+start_day+"&end_day="+end_day+"&user_id="+user_id+"&psize="+psize+"&server_id="+server_id+"&type="+type+"&examine_id="+examine_id;
    }
</script>
<ul class="nav nav-tabs">
    <li {if $status == 1}class="active"{/if} ><a href="{php echo $this->createWebUrl('finance', array('op'=>'index'))}">待确认收款</a></li>
    <li {if $status == 2}class="active"{/if}><a href="{php echo $this->createWebUrl('finance', array('op'=>'index','status' => 2))}">已确认收款</a></li>
    <!--<li ><a href="{php echo $this->createWebUrl('finance', array('op'=>'statistics'))}">收支报表</a></li>-->
</ul>
<div>
    <div>
        <div class="row">
            <div class="col-xs-3">
                {if $status == 1}
                收款日期(开始)
                {else}
                审核日期(开始)
                {/if}
            </div>
            <div class="col-xs-3">
                {if $status == 1}
                收款日期(结束)
                {else}
                审核日期(结束)
                {/if}
            </div>
            <div class="col-xs-3">搜索客户</div>
            <div class="col-xs-3">收款员</div>
            <div class="col-xs-3">
                <input type="date" id="start_day" value="{$start_day}" class="form-control" />
            </div>
            <div class="col-xs-3">
                <input type="date" id="end_day" value="{$end_day}" class="form-control" />
            </div>
            <div class="col-xs-3">
                <input type="text" id="key_word" value="{$key_word}" placeholder="客户名称/助记码/电话" class="form-control" />
            </div>
            <div class="col-xs-3">
                <select class="form-control" id="user_id">
                    <option value="0">请选择收款员</option>
                    {loop $users $user}
                    <option value="{$user['uid']}" {if $user['uid'] == $user_id} selected="selected" {/if}>{$user['name']}</option>
                    {/loop}
                </select>
            </div>

        </div>
        <br />
        <div class="row">
            <div class="col-xs-3">
                <select class="form-control" id="server_id">
                    <option value="0">服务社</option>
                    {loop $servers $server}
                    <option value="{$server['id']}" {if $server['id'] == $server_id} selected="selected" {/if}>{$server['name']}</option>
                    {/loop}
                </select>
            </div>
            <div class="col-xs-3">
                <select class="form-control" id="type">
                    <option value="0">收款类型</option>
                    <option value="freight" {if $type == 'freight'} selected="selected" {/if}>运费</option>
                    <option value="gen_pay" {if $type == 'gen_pay'} selected="selected" {/if}>代付款</option>
                </select>
            </div>
            <div class="col-xs-3">
                <select class="form-control" id="examine-id">
                    <option value="0">审核人</option>
                    {loop $users $user}
                    <option value="{$user['uid']}" {if $user['uid'] == $examine_id} selected="selected" {/if}>{$user['name']}</option>
                    {/loop}
                </select>
            </div>
            <div class="col-xs-3">
                <button class="btn btn-primary find">搜索</button>
                <button class="btn btn-primary export">导出</button>
            </div>
        </div>
        <br />
        <table class="table">
            <tr>
                <th>客户</th>
                <th>订单日期</th>
                <th>收款日期</th>
                {if $status == 2}
                <th>审核日期</th>
                <th>审核人</th>
                {/if}
                <th>商品</th>
                <th>数量</th>
                <th>运费单价</th>
                <th>应收代付款</th>
                <th>已收运费</th>
                <th>运费核销</th>
                <th>已收代付款</th>
                <th>收款员</th>
                <th>收款备注</th>
                {if $status == 1}
                <th>操作</th>
                {/if}
            </tr>
            {loop $data $d}
            <tr>
                <td>
                    {if $d['server_name']}
                    <p>{$d['server_name']}</p>
                    <p>({$d['name']})</p>
                    {else}
                    {$d['name']}
                    {/if}

                </td>
                <td>{$d['day']}</td>
                <td>
                    {$d['ml_time']}
                </td>


                {if $status == 2}
                <td>{$d['examine_time']}</td>
                <td>{$d['examine_name']}</td>
                {/if}
                <td>{$d['goods_name']}</td>
                <td>
                    {$d['numbers']}{$d['unit_name']}
                </td>
                <td>
                    {if $d['ml_type'] == 'freight'}
                    {$d['freight']}
                    {/if}
                </td>
                <td>
                    {if $d['ml_type'] == 'gen_pay'}
                    {$d['gen_pay']}
                    {/if}
                </td>
                <td>
                    {if $d['ml_type'] == 'freight'}
                    {$d['money']}
                    {/if}
                </td>
                <td>
                    {if $d['ml_type'] == 'freight'}
                    {$d['need_freight']}
                    {/if}
                </td>
                <td>
                    {if $d['ml_type'] == 'gen_pay'}
                    {$d['money']}
                    {/if}
                </td>
                <td>{$d['username']}</td>
                <td>{$d['had_remark']}</td>
                {if $status == 1}
                <td>

                    <button class="btn btn-primary examine" log_id="{$d['ml_id']}">审核</button>

                </td>
                {/if}
            </tr>
            {/loop}
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td colspan="2">
                    {if $type == 'freight'}
                    总应收运费：{$total_freight}
                    {/if}
                </td>
                <td>
                    {$total_gen}
                </td>
                <td>
                    {$total_had_freight}
                </td>
                <td>
                    {$total_need_freight}
                </td>
                <td>
                    {$total_had_gen}
                </td>
                <td></td>
                <td></td>
                <td>
                    {if $status == 1}
                    <button type="button" class="btn btn-success examine-all">全部审核</button>
                    {/if}
                </td>
            </tr>
        </table>
        <div>
            {$pager}
        </div>
        <div>
            每页显示
            <select id="page-size">
                <option value="0">显示全部</option>
                <option value="20" {if $psize == 20} selected="selected" {/if}>20</option>
                <option value="50" {if $psize == 50} selected="selected" {/if}>50</option>
                <option value="100" {if $psize == 100} selected="selected" {/if}>100</option>
                <option value="500" {if $psize == 500} selected="selected" {/if}>500</option>
                <option value="1000" {if $psize == 1000} selected="selected" {/if}>1000</option>
                <option value="5000" {if $psize == 5000} selected="selected" {/if}>5000</option>
                <option value="10000" {if $psize == 10000} selected="selected" {/if}>10000</option>
            </select>
            条
        </div>
    </div>
</div>

{template 'common/footer'}